// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;

public sealed partial class FiltersAggregation
{
	/// <summary>
	/// <para>Collection of queries from which to build buckets.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("filters")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query>? Filters { get; set; }

	/// <summary>
	/// <para>Set to `true` to add a bucket to the response which will contain all documents that do not match any of the given filters.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("other_bucket")]
	public bool? OtherBucket { get; set; }

	/// <summary>
	/// <para>The key with which the other bucket is returned.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("other_bucket_key")]
	public string? OtherBucketKey { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation(FiltersAggregation filtersAggregation) => Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation.Filters(filtersAggregation);
}

public sealed partial class FiltersAggregationDescriptor<TDocument> : SerializableDescriptor<FiltersAggregationDescriptor<TDocument>>
{
	internal FiltersAggregationDescriptor(Action<FiltersAggregationDescriptor<TDocument>> configure) => configure.Invoke(this);

	public FiltersAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query>? FiltersValue { get; set; }
	private bool? OtherBucketValue { get; set; }
	private string? OtherBucketKeyValue { get; set; }

	/// <summary>
	/// <para>Collection of queries from which to build buckets.</para>
	/// </summary>
	public FiltersAggregationDescriptor<TDocument> Filters(Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query>? filters)
	{
		FiltersValue = filters;
		return Self;
	}

	/// <summary>
	/// <para>Set to `true` to add a bucket to the response which will contain all documents that do not match any of the given filters.</para>
	/// </summary>
	public FiltersAggregationDescriptor<TDocument> OtherBucket(bool? otherBucket = true)
	{
		OtherBucketValue = otherBucket;
		return Self;
	}

	/// <summary>
	/// <para>The key with which the other bucket is returned.</para>
	/// </summary>
	public FiltersAggregationDescriptor<TDocument> OtherBucketKey(string? otherBucketKey)
	{
		OtherBucketKeyValue = otherBucketKey;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FiltersValue is not null)
		{
			writer.WritePropertyName("filters");
			JsonSerializer.Serialize(writer, FiltersValue, options);
		}

		if (OtherBucketValue.HasValue)
		{
			writer.WritePropertyName("other_bucket");
			writer.WriteBooleanValue(OtherBucketValue.Value);
		}

		if (!string.IsNullOrEmpty(OtherBucketKeyValue))
		{
			writer.WritePropertyName("other_bucket_key");
			writer.WriteStringValue(OtherBucketKeyValue);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class FiltersAggregationDescriptor : SerializableDescriptor<FiltersAggregationDescriptor>
{
	internal FiltersAggregationDescriptor(Action<FiltersAggregationDescriptor> configure) => configure.Invoke(this);

	public FiltersAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query>? FiltersValue { get; set; }
	private bool? OtherBucketValue { get; set; }
	private string? OtherBucketKeyValue { get; set; }

	/// <summary>
	/// <para>Collection of queries from which to build buckets.</para>
	/// </summary>
	public FiltersAggregationDescriptor Filters(Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query>? filters)
	{
		FiltersValue = filters;
		return Self;
	}

	/// <summary>
	/// <para>Set to `true` to add a bucket to the response which will contain all documents that do not match any of the given filters.</para>
	/// </summary>
	public FiltersAggregationDescriptor OtherBucket(bool? otherBucket = true)
	{
		OtherBucketValue = otherBucket;
		return Self;
	}

	/// <summary>
	/// <para>The key with which the other bucket is returned.</para>
	/// </summary>
	public FiltersAggregationDescriptor OtherBucketKey(string? otherBucketKey)
	{
		OtherBucketKeyValue = otherBucketKey;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FiltersValue is not null)
		{
			writer.WritePropertyName("filters");
			JsonSerializer.Serialize(writer, FiltersValue, options);
		}

		if (OtherBucketValue.HasValue)
		{
			writer.WritePropertyName("other_bucket");
			writer.WriteBooleanValue(OtherBucketValue.Value);
		}

		if (!string.IsNullOrEmpty(OtherBucketKeyValue))
		{
			writer.WritePropertyName("other_bucket_key");
			writer.WriteStringValue(OtherBucketKeyValue);
		}

		writer.WriteEndObject();
	}
}